package com.example.admin.yuejian_22.Fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.admin.yuejian_22.Listener.UserListener;
import com.example.admin.yuejian_22.Model.UserModel;
import com.example.admin.yuejian_22.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class SendCommentFragment extends Fragment {
    private EditText comment_edit;
    private Button comment_submit;
    private String id;
    private String userid;
    private String reply_userid;
    UserListener userListener = new UserListener() {
        @Override
        public void onResponse(Object beanobject) {

            Toast.makeText(getActivity(), "评论成功", Toast.LENGTH_LONG).show();
            comment_edit.setText("");

        }

        @Override
        public void onFail(String msg) {

        }
    };



    public SendCommentFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_send_comment, container, false);
        comment_edit = (EditText) view.findViewById(R.id.comment_edit);
        comment_submit = (Button) view.findViewById(R.id.comment_submit);


        Intent intent = getActivity().getIntent();
        userid = intent.getStringExtra("userid");
        id = intent.getStringExtra("shaitu_id");
        reply_userid = getActivity().getSharedPreferences("userInfo", Context.MODE_PRIVATE).getString("reply_userid", String.valueOf(0));
        comment_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String co = String.valueOf(comment_edit.getText());
                if (co.equals("")) {
                    Toast.makeText(getActivity(), "您输入的信息为空", Toast.LENGTH_LONG).show();
                } else {
                    UserModel userModel = new UserModel();
                    userModel.sendComment(id,userid,reply_userid,co,userListener);
                }

            }
        });
        //String var = 控件句柄.gettext();




        return view;
    }


}
